package com.socialcoco.controller;

import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.socialcoco.entity.UserFriend;
import com.socialcoco.exception.myExection;
import com.socialcoco.respone.BaseResponse;
import com.socialcoco.respone.ResultUtils;
import com.socialcoco.respone.resultenum;
import com.socialcoco.util.Search;
import io.swagger.annotations.ApiOperation;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.io.IOException;
import java.util.HashMap;
import java.util.List;
import java.util.Map;

@RestController
@Slf4j
@RequestMapping("/socialcoco/user")
public class SearchController {

    @Autowired
    private Search search;
    @ApiOperation("用户搜索")
    @GetMapping("/Search/{keyword}")
    public BaseResponse<Object> Search(@PathVariable String keyword,@RequestHeader("token") String token) throws IOException {
        if(keyword==null){
            throw new myExection(resultenum.BODY_NULL.getCode(),resultenum.BODY_NULL.getMsg());
        }
        List<Map<String, Object>> ContentMaps = search.SearchContent(keyword);
        List<Map<String, Object>> NameKeyword = search.SearchName(keyword);
        Map map = new HashMap();
        map.put("ContentMaps",ContentMaps);
        map.put("NameKeyword",NameKeyword);
        return ResultUtils.success(map);
    }
}
